{% include "../common/header.html" %}

<form class="form form-horizontal" id="form-article-add">
    <input type="hidden" value="" id="aid" />
    <div class="row cl">
        <input type="hidden" value="{{item.id}}" id="tid" />
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户名：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text name" value="{{item.name}}" placeholder="" id="" name="">
        </div>
    </div>
    <div class="row cl">
        <input type="hidden" value="{{item.id}}" id="tid" />
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>密码：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="password" class="input-text password" value="" placeholder="" id="" name="">
        </div>
    </div>
    <div class="row cl">
        <input type="hidden" value="{{item.id}}" id="tid" />
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>邮箱：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text email" value="{{item.email}}" placeholder="" id="" name="">
        </div>
    </div>
    <div class="row cl">
        <input type="hidden" value="{{item.id}}" id="tid" />
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属角色</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select class="" name="" id="roleSelect">
                      {% for role in roleList %}
                            <option value="{{role.id}}" {%if role.id==item.role%}selected{%endif%} > {{role.rolename}}</option>
                      {%endfor%}
                </select>
        </div>
    </div>
    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
            <button class="btn btn-secondary radius" id="savetag" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
            <button onClick="window.location.href='/{{action}}'" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
        </div>
    </div>
</form>



{% include "../common/footer.html" %}

<script>
$("#savetag").click(function(){
    var newData={
        id:$("#tid").val(),
        name:$(".name").val(),
        password:$(".password").val(),
        email:$(".email").val(),
        role:$("#roleSelect").val(),
    }
    $.ajax({
        url:'/user/save',
        data:newData,
        type:'POST',
        success:function(json){
            if(json.errno===0){
                alert("保存成功！");
                window.location.href="/user"
            }else{
                alert(json.errmsg)
            }
        }
    })
})


</script>
